package com.cjx.yuanshenstartforumbackend.config;

import com.cjx.yuanshenstartforumbackend.interceptor.LoginInterceptors;
import com.cjx.yuanshenstartforumbackend.interceptor.RefreshTokenInterceptor;
import org.springframework.cglib.transform.impl.AddInitTransformer;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Description SpringMVC相关的配置
 * @Author cjx
 * @Date 2023/12/22 21:21
 **/
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置登录拦截器
        registry.addInterceptor(new LoginInterceptors())
                .excludePathPatterns(
                        "/user/login",
                        "/user/registerUser",
                        "/user/checkUserName"
                ).order(1);
        //配置token刷新拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate))
                .addPathPatterns("/**").order(0);
    }
}
